<%@ page contentType="text/html;charset=GB2312"
	import="java.sql.*,java.util.Date,java.text.ParsePosition,java.text.DateFormat,java.text.SimpleDateFormat,java.util.*,java.util.Calendar,cs5226.GetCurrentTime"%>

<html>
	<head>
		<title>Dashboard login</title>
	</head>
	<body>
		<%
			float high311, middle311, low311, high312, middle312, low312, high321, middle321, low321, high3221, middle3221, low3221, high3222, middle3222, low3222, Hit_ratioh, Hit_ratiom, Hit_ratiol, high34, middle34, low34;

			String cTime;
			cs5226.GetCurrentTime gcth = new cs5226.GetCurrentTime();
			cs5226.GetCurrentTime gctm = new cs5226.GetCurrentTime();
			cs5226.GetCurrentTime gctl = new cs5226.GetCurrentTime();

			//     gct.getTime().add(Calendar.HOUR,25);

			String year = Integer.toString(gcth.getyear());
			String month;
			String hour;
			String date;
			String minute;
			String second;
			String starttimeh, starttimem, endtime, starttimel;
			if (gcth.getmonth() < 10)
				month = "0" + gcth.getmonth();
			else
				month = "" + gcth.getmonth();

			if (gcth.getdate() < 10)
				date = "0" + gcth.getdate();
			else
				date = "" + gcth.getdate();

			if (gcth.getTime().get(Calendar.HOUR_OF_DAY) < 10)
				hour = "0" + gcth.getTime().get(Calendar.HOUR_OF_DAY);
			else
				hour = "" + gcth.getTime().get(Calendar.HOUR_OF_DAY);

			if (gcth.getminute() < 10)
				minute = "0" + gcth.getminute();
			else
				minute = "" + gcth.getminute();

			if (gcth.getsecond() < 10)
				second = "0" + gcth.getsecond();
			else
				second = "" + gcth.getsecond();

			cTime = year + "-" + month + "-" + date + "-" + hour + "-" + minute
					+ "-" + second;

			/////high

			gcth.getTime().add(Calendar.DATE, -7);

			if (gcth.getmonth() < 10)
				month = "0" + gcth.getmonth();
			else
				month = "" + gcth.getmonth();

			if (gcth.getdate() < 10)
				date = "0" + gcth.getdate();
			else
				date = "" + gcth.getdate();

			if (gcth.getTime().get(Calendar.HOUR_OF_DAY) < 10)
				hour = "0" + gcth.getTime().get(Calendar.HOUR_OF_DAY);
			else
				hour = "" + gcth.getTime().get(Calendar.HOUR_OF_DAY);

			if (gcth.getminute() < 10)
				minute = "0" + gcth.getminute();
			else
				minute = "" + gcth.getminute();

			if (gcth.getsecond() < 10)
				second = "0" + gcth.getsecond();
			else
				second = "" + gcth.getsecond();

			starttimeh = year + "-" + month + "-" + date + "-" + hour + "-"
					+ minute + "-" + second;
			////////////----h

			/////middle

			gctm.getTime().add(Calendar.HOUR, -1);

			if (gctm.getmonth() < 10)
				month = "0" + gctm.getmonth();
			else
				month = "" + gctm.getmonth();

			if (gctm.getdate() < 10)
				date = "0" + gctm.getdate();
			else
				date = "" + gctm.getdate();

			if (gctm.getTime().get(Calendar.HOUR_OF_DAY) < 10)
				hour = "0" + gctm.getTime().get(Calendar.HOUR_OF_DAY);
			else
				hour = "" + gctm.getTime().get(Calendar.HOUR_OF_DAY);

			if (gctm.getminute() < 10)
				minute = "0" + gctm.getminute();
			else
				minute = "" + gctm.getminute();

			if (gctm.getsecond() < 10)
				second = "0" + gctm.getsecond();
			else
				second = "" + gctm.getsecond();

			starttimem = year + "-" + month + "-" + date + "-" + hour + "-"
					+ minute + "-" + second;
			////////////----m

			/////low

			gctl.getTime().add(Calendar.HOUR, -1);

			if (gctl.getmonth() < 10)
				month = "0" + gctl.getmonth();
			else
				month = "" + gctl.getmonth();

			if (gctl.getdate() < 10)
				date = "0" + gctl.getdate();
			else
				date = "" + gctl.getdate();

			if (gctl.getTime().get(Calendar.HOUR_OF_DAY) < 10)
				hour = "0" + gctl.getTime().get(Calendar.HOUR_OF_DAY);
			else
				hour = "" + gctl.getTime().get(Calendar.HOUR_OF_DAY);

			if (gctl.getminute() < 10)
				minute = "0" + gctl.getminute();
			else
				minute = "" + gctl.getminute();

			if (gctl.getsecond() < 10)
				second = "0" + gctl.getsecond();
			else
				second = "" + gctl.getsecond();

			starttimel = year + "-" + month + "-" + date + "-" + hour + "-"
					+ minute + "-" + second;
			////////////----l

			endtime = cTime;
			String sql311h = "select sum(GETMISSES)/sum(GETS) \"DIC_HIT_RATIO\" from dba_hist_rowcache_summary a, dba_hist_snapshot b where a.SNAP_ID =b.SNAP_ID and (b.END_INTERVAL_TIME>=to_timestamp('"
					+ starttimeh
					+ "','YYYY-MM-DD-HH24-MI-SS') and b.END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql311m = "select sum(GETMISSES)/sum(GETS) \"DIC_HIT_RATIO\" from dba_hist_rowcache_summary a, dba_hist_snapshot b where a.SNAP_ID =b.SNAP_ID and (b.END_INTERVAL_TIME>=to_timestamp('"
					+ starttimem
					+ "','YYYY-MM-DD-HH24-MI-SS') and b.END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql311l = "select sum(GETMISSES)/sum(GETS) \"DIC_HIT_RATIO\" from dba_hist_rowcache_summary a, dba_hist_snapshot b where a.SNAP_ID =b.SNAP_ID and (b.END_INTERVAL_TIME>=to_timestamp('"
					+ starttimel
					+ "','YYYY-MM-DD-HH24-MI-SS') and b.END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))";

			String sql312h = "select sum(PINHITS)/sum(PINS) \"Lib_Hit_Ratio\" from  dba_hist_librarycache  where SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimeh
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql312m = "select sum(PINHITS)/sum(PINS) \"Lib_Hit_Ratio\" from  dba_hist_librarycache  where SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimem
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql312l = "select sum(PINHITS)/sum(PINS) \"Lib_Hit_Ratio\" from  dba_hist_librarycache  where SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimel
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))";

			String sql321h = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='physical reads cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimeh
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql321m = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='physical reads cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimem
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql321l = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='physical reads cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimel
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))";

			String sql3221h = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='consistent gets from cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimeh
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql3221m = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='consistent gets from cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimem
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql3221l = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='consistent gets from cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimel
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql3222h = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='db block gets from cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimeh
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql3222m = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='db block gets from cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimem
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql3222l = "select sum(VALUE) from dba_hist_sysstat where STAT_NAME='db block gets from cache' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimel
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))";

			//sql341h = "select sum(VALUE) \"sorts in memory\" from dba_hist_sysstat where STAT_NAME = 'sorts (memory)' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"+starttimeh+"','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"+endtime+"','YYYY-MM-DD-HH24-MI-SS')+(1/96)))",
			//sql341m = "select sum(VALUE) \"sorts in memory\" from dba_hist_sysstat where STAT_NAME = 'sorts (memory)' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"+starttimeh+"','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"+endtime+"','YYYY-MM-DD-HH24-MI-SS')+(1/96)))",
			//sql341l = "select sum(VALUE) \"sorts in memory\" from dba_hist_sysstat where STAT_NAME = 'sorts (memory)' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"+starttimeh+"','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"+endtime+"','YYYY-MM-DD-HH24-MI-SS')+(1/96)))",
			//sql342h = "select sum(VALUE) \"sorts in disk\" from dba_hist_sysstat where STAT_NAME = 'sorts (disk)' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"+starttimeh+"','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"+endtime+"','YYYY-MM-DD-HH24-MI-SS')+(1/96)))",
			// sql342m = "select sum(VALUE) \"sorts in disk\" from dba_hist_sysstat where STAT_NAME = 'sorts (disk)' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"+starttimeh+"','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"+endtime+"','YYYY-MM-DD-HH24-MI-SS')+(1/96)))",
			// sql342l = "select sum(VALUE) \"sorts in disk\" from dba_hist_sysstat where STAT_NAME = 'sorts (disk)' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"+starttimeh+"','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"+endtime+"','YYYY-MM-DD-HH24-MI-SS')+(1/96)))",
			String sql34h = "select sum(VALUE)/count(VALUE) \"cache hit percentage\" from dba_hist_pgastat where NAME='cache hit percentage' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimeh
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql34m = "select sum(VALUE)/count(VALUE) \"cache hit percentage\" from dba_hist_pgastat where NAME='cache hit percentage' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimem
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))", sql34l = "select sum(VALUE)/count(VALUE) \"cache hit percentage\" from dba_hist_pgastat where NAME='cache hit percentage' and SNAP_ID in (select SNAP_ID from dba_hist_snapshot where END_INTERVAL_TIME>=to_timestamp('"
					+ starttimel
					+ "','YYYY-MM-DD-HH24-MI-SS') and END_INTERVAL_TIME<=(to_timestamp('"
					+ endtime + "','YYYY-MM-DD-HH24-MI-SS')+(1/96)))";

			//		    System.out.println(sql311h);
			Connection connectionR = null;
			try {
				// Load the JDBC driver
				String driverName = "oracle.jdbc.driver.OracleDriver";
				Class.forName(driverName);
				// ORACLE_SID=orcl
				// Create a connection to the database
				String serverName = "127.0.0.1";
				String portNumber = "1521";
				String sid = "xe";
				String url = "jdbc:oracle:thin:@" + serverName + ":"
				+ portNumber + ":" + sid;
				String username = "system";
				String password = "040718wing";
				connectionR = DriverManager.getConnection(url, username,
				password);

			} catch (ClassNotFoundException e) {
				System.out.println("Could not find the database driver");
			} catch (SQLException e) {
				System.out.println("Could not connect to the database");
			}

			Statement st311h = null;
			Statement st311m = null;
			Statement st311l = null;

			Statement st312h = null;
			Statement st312m = null;
			Statement st312l = null;

			Statement st321h = null;
			Statement st321m = null;
			Statement st321l = null;

			Statement st3221h = null;
			Statement st3221m = null;
			Statement st3221l = null;

			Statement st3222h = null;
			Statement st3222m = null;
			Statement st3222l = null;

			Statement st34h = null;
			Statement st34m = null;
			Statement st34l = null;

			try {
				st311h = connectionR.createStatement();
				st311m = connectionR.createStatement();
				st311l = connectionR.createStatement();

				st312h = connectionR.createStatement();
				st312m = connectionR.createStatement();
				st312l = connectionR.createStatement();

				st321h = connectionR.createStatement();
				st321m = connectionR.createStatement();
				st321l = connectionR.createStatement();

				st3221h = connectionR.createStatement();
				st3221m = connectionR.createStatement();
				st3221l = connectionR.createStatement();

				st3222h = connectionR.createStatement();
				st3222m = connectionR.createStatement();
				st3222l = connectionR.createStatement();

				st34h = connectionR.createStatement();
				st34m = connectionR.createStatement();
				st34l = connectionR.createStatement();

				ResultSet rs311h = st311h.executeQuery(sql311h), rs311m = st311m
				.executeQuery(sql311m), rs311l = st311l
				.executeQuery(sql311l);
				rs311h.next();
				rs311m.next();
				rs311l.next();
				high311 = rs311h.getFloat(1);
				middle311 = rs311m.getFloat(1);
				low311 = rs311l.getFloat(1);

				ResultSet rs312h = st312h.executeQuery(sql312h), rs312m = st312m
				.executeQuery(sql312m), rs312l = st312l
				.executeQuery(sql312l);
				rs312h.next();
				rs312m.next();
				rs312l.next();
				high312 = rs312h.getFloat(1);
				middle312 = rs312m.getFloat(1);
				low312 = rs312l.getFloat(1);

				ResultSet rs321h = st321h.executeQuery(sql321h), rs321m = st321m
				.executeQuery(sql321m), rs321l = st321l
				.executeQuery(sql321l);
				rs321h.next();
				rs321m.next();
				rs321l.next();
				high321 = rs321h.getFloat(1);
				middle321 = rs321m.getFloat(1);
				low321 = rs321l.getFloat(1);

				ResultSet rs3221h = st3221h.executeQuery(sql3221h), rs3221m = st3221m
				.executeQuery(sql3221m), rs3221l = st3221l
				.executeQuery(sql3221l);
				rs3221h.next();
				rs3221m.next();
				rs3221l.next();
				high3221 = rs3221h.getFloat(1);
				middle3221 = rs3221m.getFloat(1);
				low3221 = rs3221l.getFloat(1);

				ResultSet rs3222h = st3222h.executeQuery(sql3222h), rs3222m = st3222m
				.executeQuery(sql3222m), rs3222l = st3222l
				.executeQuery(sql3222l);
				rs3222h.next();
				rs3222m.next();
				rs3222l.next();
				high3222 = rs3222h.getFloat(1);
				middle3222 = rs3222m.getFloat(1);
				low3222 = rs3222l.getFloat(1);

				Hit_ratioh = 1 - (high321 / (high3221 + high3222));
				Hit_ratiom = 1 - (middle321 / (middle3221 + middle3222));
				Hit_ratiol = 1 - (low321 / (low3221 + low3222));

				ResultSet rs34h = st34h.executeQuery(sql34h), rs34m = st34m
				.executeQuery(sql34m), rs34l = st34l
				.executeQuery(sql34l);
				rs34h.next();
				rs34m.next();
				rs34l.next();
				high34 = rs34h.getFloat(1);
				if (high34 > 1) {
					high34 = 1;
				}
				middle34 = rs34m.getFloat(1);
				if (middle34 > 1) {
					middle34 = 1;
				}
				low34 = rs34l.getFloat(1);
				if (low34 > 1) {
					low34 = 1;
				}

				session.setAttribute("high311", new Float(high311 * 100));
				session.setAttribute("middle311", new Float(middle311 * 100));
				session.setAttribute("low311", new Float(low311 * 100));

				session.setAttribute("high312", new Float(high312 * 100));
				session.setAttribute("middle312", new Float(middle312 * 100));
				session.setAttribute("low312", new Float(low312 * 100));

				session.setAttribute("Hit_ratioh", new Float(Hit_ratioh * 100));
				session.setAttribute("Hit_ratiom", new Float(Hit_ratiom * 100));
				session.setAttribute("Hit_ratiol", new Float(Hit_ratiol * 100));

				session.setAttribute("high34", new Float(high34 * 100));
				session.setAttribute("middle34", new Float(middle34 * 100));
				session.setAttribute("low34", new Float(low34 * 100));

				rs312l.close();
				rs312m.close();
				rs312h.close();

				rs311l.close();
				rs311m.close();
				rs311h.close();

				rs321l.close();
				rs321m.close();
				rs321h.close();

				rs3221l.close();
				rs3221m.close();
				rs3221h.close();

				rs3222l.close();
				rs3222m.close();
				rs3222h.close();

				rs34l.close();
				rs34m.close();
				rs34h.close();

				st311h.close();
				st311m.close();
				st311l.close();

			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			String userName = request.getParameter("User");
			String Password = request.getParameter("Pwd");
			if (userName == null || Password == null || userName.equals("")
					|| Password.equals("")) {
				response.sendRedirect("index.jsp");
				return;
			}

			String sql = "select * from USER_DB where NAME='" + userName
					+ "' and PASSWORD='" + Password + "'";
			Connection connection = null;
			try {
				// Load the JDBC driver
				String driverName = "oracle.jdbc.driver.OracleDriver";
				Class.forName(driverName);
				// ORACLE_SID=orcl
				// Create a connection to the database
				String serverName = "127.0.0.1";
				String portNumber = "1521";
				String sid = "xe";
				String url = "jdbc:oracle:thin:@" + serverName + ":"
				+ portNumber + ":" + sid;
				String username = "hr";
				String password = "040718";
				connection = DriverManager.getConnection(url, username,
				password);

			} catch (ClassNotFoundException e) {
				System.out.println("Could not find the database driver");
			} catch (SQLException e) {
				System.out.println("Could not connect to the database");
			}

			Statement st = null;
			try {
				st = connection.createStatement();
				ResultSet rs = st.executeQuery(sql);

				// System.out.print("111");
				if (rs.next()) {
					response.sendRedirect("test.jsp");
				} else {
					response.sendRedirect("index.jsp");
				}
				rs.close();
				st.close();

			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		%>

	</body>
</html>